问题
需要在OpenWrt创建服务,但是OpenWrt使用的init.d方式进行服务设置的。
解决
init.d脚本
在文件夹/etc/init.d/中,创建对应的启动服务脚本,例如:/etc/init.d/example
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=10
STOP=15
start() {
echo start
# commands to launch application
}
stop() {
echo stop
# commands to kill application
}
注意,这里/etc/rc.common这里需要继承的父init.d脚本,这样我们自己的脚本只要实现start和stop即可,不用关心通用的enable和disable的实现,至于start和stop的具体实现,可以参考之前介绍的init.d脚本模板。
使用service
# 启动服务
service example start
# 停止服务
service example stop
# 启用开机自启动
service example enable
luci中管理启动项
![luci中管理服务](https://img-blog.csdnimg.cn/20210509065645369.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Z4dHh6Mg==,size_16,color_FFFFFF,t_70)
参考:
Init Scripts
|